import collections
class Solution(object):
    def numPairsDivisibleBy60(self, time):
        c = 0
        d = collections.defaultdict(int)
        for t in time:
            t %= 60
            c += d[(60 - t) % 60]
            d[t] += 1
        return c



data = Solution()
time = [30, 20, 150, 100, 40]
print(data.numPairsDivisibleBy60(time))
